package com.wkc.adapter;


import java.util.ArrayList;
import java.util.List;

import com.wkc.data.ListItem;

import wwk.common.util.ImageLoader;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.wkc.R;
/**
 * 
 * @author Administrator
 *
 */

public class ItemListAdapter extends BaseAdapter 
{
	private LayoutInflater mInflater;
	List<ListItem> itemArray=new ArrayList<ListItem>(20);
	public ImageLoader imageLoader;

	public ItemListAdapter(Context context)
	{
		mInflater = LayoutInflater.from(context);
		
		imageLoader=new ImageLoader(context);
		imageLoader.defaultImageId=R.drawable.default_icon;
	}
	
	public void addListItem(ListItem listItem)
	{
		itemArray.add(listItem);
	}
	
	public void insertListItem(ListItem listItem)
	{
		itemArray.add(0, listItem);
	}

	public int getCount()
	{
		int size=itemArray.size();
		return size;
	}

	public long getItemId(int position)
	{
		//return position;
		return itemArray.get(position).id;
	}
	
	public Object getItem(int position) {
        //return position;
		return itemArray.get(position);
    }

	public View getView(int position, View convertView, ViewGroup parent)
	{
        if (convertView == null) 
        {
            convertView = mInflater.inflate(R.layout.common_image_text_under_text_image, null);
        }
        
        ListItem item=itemArray.get(position);
        
        TextView textView=(TextView)convertView.findViewById(R.id.textView);
        textView.setText(item.title);
        
        textView=(TextView)convertView.findViewById(R.id.underTextView);
        textView.setText(item.datetime);
        
        textView=(TextView)convertView.findViewById(R.id.rightTextView);
        textView.setText("");
        
        ImageView imageView=(ImageView)convertView.findViewById(R.id.leftImageView);
        imageView.setImageResource(R.drawable.default_icon);
        imageLoader.displayImage(item.thumbnailUrl,imageView);

        return convertView;
	}
}
